package com.chinanet.netelementmodel;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 *
 */
public class BcFromzzogg_Imp implements WorkInterFace {
    private static final String RES_URL = "http://172.20.4.12/monitor/bcbyzzogg/findBcData";


    public String getName() {
        return "新-资源系统用户信息查询";
    }

    public String getDesciption() {
        return "";
    }

    public int getVersion() {
        return 0;
    }

    public Attr[] getInAttrs() {
        Attr[] in = new Attr[1];
        in[0] = new Attr("accesscode", "通用账号", AttrType.TYPE_String, true);
        return in;
    }

    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[83];
        out[0] = new Attr("flag", "操作是否成功，0：成功，1：失败", AttrType.TYPE_Int, true);
        out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
//        itv
        out[2] = new Attr("itv_broadbandAccount", "ITV-宽带账号", AttrType.TYPE_String, true);
        out[3] = new Attr("itv_customerName", "ITV-客户名称", AttrType.TYPE_String, true);
        out[4] = new Attr("itv_snNumber", "ITV-SN号", AttrType.TYPE_String, true);
        out[5] = new Attr("itv_serviceNumber", "ITV-业务号码", AttrType.TYPE_String, true);
        out[6] = new Attr("itv_accessType", "ITV-接入类型", AttrType.TYPE_String, true);
        out[7] = new Attr("itv_status", "ITV-状态", AttrType.TYPE_String, true);
        out[8] = new Attr("itv_plane", "ITV-平面", AttrType.TYPE_String, true);
        out[9] = new Attr("itv_line", "ITV-线路", AttrType.TYPE_String, true);
        out[10] = new Attr("itv_direction", "ITV-局向", AttrType.TYPE_String, true);
        out[11] = new Attr("itv_vpi", "ITV-VPI", AttrType.TYPE_String, true);
        out[12] = new Attr("itv_vci", "ITV-VCI", AttrType.TYPE_String, true);
        out[13] = new Attr("itv_port", "ITV-端口", AttrType.TYPE_String, true);
        out[14] = new Attr("itv_portRate", "ITV-端口速率", AttrType.TYPE_String, true);
        out[15] = new Attr("itv_networkElement", "ITV-所属网元", AttrType.TYPE_String, true);
        out[16] = new Attr("itv_deviceIpaddress", "ITV-设备IP地址", AttrType.TYPE_String, true);
        out[17] = new Attr("itv_oltName", "ITV-OLT名称", AttrType.TYPE_String, true);
        out[18] = new Attr("itv_oltIp", "ITV-OLTIP", AttrType.TYPE_String, true);
        out[19] = new Attr("itv_oltAssembly", "ITV-OLT拼装", AttrType.TYPE_String, true);
        out[20] = new Attr("itv_ponPortAssemblyName", "ITV-PON口拼装名称", AttrType.TYPE_String, true);
        out[21] = new Attr("itv_AssemblyCode", "ITV-拼装编码", AttrType.TYPE_String, true);
        out[22] = new Attr("itv_ponPort", "ITV-PON口", AttrType.TYPE_String, true);
        out[23] = new Attr("itv_ponEncoding", "ITV-PON编码", AttrType.TYPE_String, true);
        out[24] = new Attr("itv_tvInnerLayer", "ITV-TV内层", AttrType.TYPE_String, true);
        out[25] = new Attr("itv_tvOuterLayer", "ITV-TV外层", AttrType.TYPE_String, true);
        out[26] = new Attr("itv_limitOutNetAccess", "ITV-限制外网访问", AttrType.TYPE_String, true);
        out[27] = new Attr("itv_fstatus", "ITV-状态", AttrType.TYPE_String, true);

        out[28] = new Attr("broadband_broadbandAccount", "宽带查询-宽带账号", AttrType.TYPE_String, true);
        out[29] = new Attr("broadband_customerName", "宽带查询-客户名称", AttrType.TYPE_String, true);
        out[30] = new Attr("broadband_snNumber", "宽带查询-SN号", AttrType.TYPE_String, true);
        out[31] = new Attr("broadband_serviceNumber", "宽带查询-业务号码", AttrType.TYPE_String, true);
        out[32] = new Attr("broadband_accessType", "宽带查询-接入类型", AttrType.TYPE_String, true);
        out[32] = new Attr("broadband_status", "宽带查询-状态", AttrType.TYPE_String, true);
        out[33] = new Attr("broadband_plane", "宽带查询-平面", AttrType.TYPE_String, true);
        out[34] = new Attr("broadband_line", "宽带查询-线路", AttrType.TYPE_String, true);
        out[35] = new Attr("broadband_direction", "宽带查询-局向", AttrType.TYPE_String, true);
        out[36] = new Attr("broadband_vpi", "宽带查询-VPI", AttrType.TYPE_String, true);
        out[37] = new Attr("broadband_vci", "宽带查询-VCI", AttrType.TYPE_String, true);
        out[38] = new Attr("broadband_port", "宽带查询-端口", AttrType.TYPE_String, true);
        out[39] = new Attr("broadband_portRate", "宽带查询-端口速率", AttrType.TYPE_String, true);
        out[40] = new Attr("broadband_networkElement", "宽带查询-所属网元", AttrType.TYPE_String, true);
        out[41] = new Attr("broadband_deviceIpaddress", "宽带查询-设备IP地址", AttrType.TYPE_String, true);
        out[42] = new Attr("broadband_oltName", "宽带查询-OLT名称", AttrType.TYPE_String, true);
        out[43] = new Attr("broadband_oltIp", "宽带查询-OLTIP", AttrType.TYPE_String, true);
        out[44] = new Attr("broadband_oltAssembly", "宽带查询-OLT拼装", AttrType.TYPE_String, true);
        out[45] = new Attr("broadband_ponPortAssemblyName", "宽带查询-PON口拼装名称", AttrType.TYPE_String, true);
        out[46] = new Attr("broadband_AssemblyCode", "宽带查询-拼装编码", AttrType.TYPE_String, true);
        out[47] = new Attr("broadband_ponPort", "宽带查询-PON口", AttrType.TYPE_String, true);
        out[48] = new Attr("broadband_ponEncoding", "宽带查询-PON编码", AttrType.TYPE_String, true);
        out[49] = new Attr("broadband_broadbanInnerLayer", "宽带查询-宽带内层", AttrType.TYPE_String, true);
        out[50] = new Attr("broadband_broadbanOuterLayer", "宽带查询-宽带外层", AttrType.TYPE_String, true);
        out[51] = new Attr("broadband_limitOutNetAccess", "宽带查询-限制外网访问", AttrType.TYPE_String, true);
        out[52] = new Attr("broadband_fstatus", "宽带查询-状态", AttrType.TYPE_String, true);
//        普通电话
        out[53] = new Attr("voice_generalPhone", "普通电话-普通电话", AttrType.TYPE_String, true);
        out[54] = new Attr("voice_physicalNumber", "普通电话-物理号码", AttrType.TYPE_String, true);
        out[55] = new Attr("voice_customerName", "普通电话-客户名称", AttrType.TYPE_String, true);
        out[56] = new Attr("voice_cornet", "普通电话-短号", AttrType.TYPE_String, true);
        out[57] = new Attr("voice_direction", "普通电话-局向", AttrType.TYPE_String, true);
        out[58] = new Attr("voice_status", "普通电话-状态", AttrType.TYPE_String, true);
        out[59] = new Attr("voice_line", "普通电话-线路", AttrType.TYPE_String, true);
        out[60] = new Attr("voice_accessType", "普通电话-接入类型", AttrType.TYPE_String, true);
        out[61] = new Attr("voice_plane", "普通电话-平面", AttrType.TYPE_String, true);
        out[62] = new Attr("voice_interfaceAssemblyName", "普通电话-接口拼装名称", AttrType.TYPE_String, true);
        out[63] = new Attr("voice_portAssemblyCode", "普通电话-端口拼装编码", AttrType.TYPE_String, true);
        out[64] = new Attr("voice_fstatus", "普通电话-状态", AttrType.TYPE_String, true);
//        sn查询
        out[65] = new Attr("sn_oltEncoding", "sn查询-OLT编码", AttrType.TYPE_String, true);
        out[66] = new Attr("sn_oltName", "sn查询-OLT名称", AttrType.TYPE_String, true);
        out[67] = new Attr("sn_oltIp", "sn查询-OLTIP", AttrType.TYPE_String, true);
        out[68] = new Attr("sn_ponEncoding", "sn查询-PON编码", AttrType.TYPE_String, true);
        out[69] = new Attr("sn_ponName", "sn查询-PON名称", AttrType.TYPE_String, true);
        out[70] = new Attr("sn_broadbandPVLAN", "sn查询-宽带PVLAN", AttrType.TYPE_String, true);
        out[71] = new Attr("sn_tvPVLAN", "sn查询-TVPVLAN", AttrType.TYPE_String, true);
        out[72] = new Attr("sn_broadbandCVLAN", "sn查询-宽带CVLAN", AttrType.TYPE_String, true);
        out[73] = new Attr("sn_tvCVLAN", "sn查询-TVCVLAN", AttrType.TYPE_String, true);
        out[74] = new Attr("sn_OLTgroupName", "OLT集团名称", AttrType.TYPE_String, true);
        out[75] = new Attr("sn_OLTgroupCode", "OLT集团编码", AttrType.TYPE_String, true);
        out[76] = new Attr("sn_PONgroupName", "PON口集团名称", AttrType.TYPE_String, true);
        out[77] = new Attr("sn_PONgroupCode", "PON口集团编码", AttrType.TYPE_String, true);

        out[78] = new Attr("itvExist", "itv是否存在；0：存在；1：不存在", AttrType.TYPE_Int, true);
        out[79] = new Attr("broadbandExist", "宽带是否存在；0：存在；1：不存在", AttrType.TYPE_Int, true);
        out[80] = new Attr("voiceExist", "语音是否存在；0：存在；1：不存在", AttrType.TYPE_Int,  true);
        out[81] = new Attr("snExist", "sn是否存在；0：存在；1：不存在", AttrType.TYPE_Int,  true);

        out[82] = new Attr("PONID","PONID",AttrType.TYPE_String,true);
        return out;
    }

    public Map<String, Object> init(Map<String, Object> data) {
         String account = (String)data.get("accesscode");
         if(StringUtils.isNotBlank(account)){
             account=account.trim();
             if(account.startsWith("tv")&&!account.endsWith("@itv")){
                 account=account+"@itv";
             }
             return getRES(account);
         }else {
             Map<String,Object> reply = new HashMap<String,Object>();
             reply.put("flag","1");
             reply.put("log", "网元能力入参数有误");
             return reply;
         }
    }

    /**
     * 查询接口
     * @param account 用户账号
     * @return
     */
    private static Map<String,Object> getRES(String account){
        String resp = null;
        Map<String,Object> reply = new HashMap<String,Object>();
        try {
            resp = doPost(RES_URL,account);
            if(StringUtils.isNotBlank(resp)){
                if(resp.equals("404")){
                    reply.put("flag","1");
                    reply.put("log", "资源请求服务器失败无响应");
                    return reply;
                }
                JSONObject jsonOut = JSON.parseObject(resp);

                if(jsonOut.getIntValue("flag")==0) {
                    JSONArray itvarrayOut = jsonOut.getJSONArray("itv");
                    JSONArray broadbandarrayOut = jsonOut.getJSONArray("broadband");
                    JSONArray voicearrayOut = jsonOut.getJSONArray("voice");
                    JSONArray pipinfoarrayOut = jsonOut.getJSONArray("pipinfo");
                    String log = "";
                    String ponid="";
                    int itvExist=1;
                    int broadbandExist=1;
                    int voiceExist=1;
                    int snExist=1;

                   // itv

                    if(itvarrayOut!=null&&itvarrayOut.size()>0&&itvarrayOut.getJSONObject(0)!=null) {
                        for (int i = 0; i < itvarrayOut.size(); i++) {
                            JSONObject object = itvarrayOut.getJSONObject(i);
                            itvExist=0;
                            if (StringUtils.isBlank(((String) reply.get("itv_broadbandAccount"))))
                                reply.put("itv_broadbandAccount", dealString(object.getString("itv_broadbandAccount")).replaceAll("@itv",""));
                            if (StringUtils.isBlank(((String) reply.get("itv_customerName"))))
                                reply.put("itv_customerName", dealString(object.getString("itv_customerName")));
                            if (StringUtils.isBlank(((String) reply.get("itv_snNumber"))))
                                reply.put("itv_snNumber", dealString(object.getString("itv_snNumber")));
                            if (StringUtils.isBlank(((String) reply.get("itv_serviceNumber"))))
                                reply.put("itv_serviceNumber", dealString(object.getString("itv_serviceNumber")));
                            if (StringUtils.isBlank(((String) reply.get("itv_accessType"))))
                                reply.put("itv_accessType", dealString(object.getString("itv_accessType")));
                            if (StringUtils.isBlank(((String) reply.get("itv_status"))))
                                reply.put("itv_status", dealString(object.getString("itv_status")));
                            if (StringUtils.isBlank(((String) reply.get("itv_plane"))))
                                reply.put("itv_plane", dealString(object.getString("itv_plane")));
                            if (StringUtils.isBlank(((String) reply.get("itv_line"))))
                                reply.put("itv_line", dealString(object.getString("itv_line")));
                            if (StringUtils.isBlank(((String) reply.get("itv_direction"))))
                                reply.put("itv_direction", dealString(object.getString("itv_direction")));
                            if (StringUtils.isBlank(((String) reply.get("itv_vpi"))))
                                reply.put("itv_vpi", dealString(object.getString("itv_vpi")));
                            if (StringUtils.isBlank(((String) reply.get("itv_vci"))))
                                reply.put("itv_vci", dealString(object.getString("itv_vci")));
                            if (StringUtils.isBlank(((String) reply.get("itv_port"))))
                                reply.put("itv_port", dealString(object.getString("itv_port")));
                            if (StringUtils.isBlank(((String) reply.get("itv_portRate"))))
                                reply.put("itv_portRate", dealString(object.getString("itv_portRate")));
                            if (StringUtils.isBlank(((String) reply.get("itv_networkElement"))))
                                reply.put("itv_networkElement", dealString(object.getString("itv_networkElement")));
                            if (StringUtils.isBlank(((String) reply.get("itv_deviceIpaddress"))))
                                reply.put("itv_deviceIpaddress", dealString(object.getString("itv_deviceIpaddress")));
                            if (StringUtils.isBlank(((String) reply.get("itv_oltName"))))
                                reply.put("itv_oltName", dealString(object.getString("itv_oltName")));
                            if (StringUtils.isBlank(((String) reply.get("itv_oltIp"))))
                                reply.put("itv_oltIp", dealString(object.getString("itv_oltIp")));
                            if (StringUtils.isBlank(((String) reply.get("itv_oltAssembly"))))
                                reply.put("itv_oltAssembly", dealString(object.getString("itv_oltAssembly")));
                            if (StringUtils.isBlank(((String) reply.get("itv_ponPortAssemblyName"))))
                                reply.put("itv_ponPortAssemblyName", dealString(object.getString("itv_ponPortAssemblyName")));
                            if (StringUtils.isBlank(((String) reply.get("itv_AssemblyCode")))) {
                                String str=dealString(object.getString("itv_AssemblyCode"));
                                reply.put("itv_AssemblyCode",str );
                            }
                            if (StringUtils.isBlank(((String) reply.get("itv_ponPort"))))
                                reply.put("itv_ponPort", dealString(object.getString("itv_ponPort")));
                            if (StringUtils.isBlank(((String) reply.get("itv_ponEncoding"))))
                                reply.put("itv_ponEncoding", dealString(object.getString("itv_ponEncoding")));
                            if (StringUtils.isBlank(((String) reply.get("itv_tvInnerLayer"))))
                                reply.put("itv_tvInnerLayer", dealString(object.getString("itv_tvInnerLayer")));
                            if (StringUtils.isBlank(((String) reply.get("itv_tvOuterLayer"))))
                                reply.put("itv_tvOuterLayer", dealString(object.getString("itv_tvOuterLayer")));
                            if (StringUtils.isBlank(((String) reply.get("itv_limitOutNetAccess"))))
                                reply.put("itv_limitOutNetAccess", dealString(object.getString("itv_limitOutNetAccess")));
                            if (StringUtils.isBlank(((String) reply.get("itv_fstatus"))))
                                reply.put("itv_fstatus", dealString(object.getString("itv_fstatus")));

                            //取得资源对象 object
                            log += object.toJSONString();
                        }
                    }


                    if(broadbandarrayOut!=null&&broadbandarrayOut.size()>0&&broadbandarrayOut.getJSONObject(0)!=null) {

                        for (int i = 0; i < broadbandarrayOut.size(); i++) {
                            JSONObject object = broadbandarrayOut.getJSONObject(i);
                            broadbandExist=0;
                            if (StringUtils.isBlank(((String) reply.get("broadband_broadbandAccount"))))
                                reply.put("broadband_broadbandAccount", dealString(object.getString("broadband_broadbandAccount")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_customerName"))))
                                reply.put("broadband_customerName", dealString(object.getString("broadband_customerName")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_snNumber"))))
                                reply.put("broadband_snNumber", dealString(object.getString("broadband_snNumber")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_serviceNumber"))))
                                reply.put("broadband_serviceNumber", dealString(object.getString("broadband_serviceNumber")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_accessType"))))
                                reply.put("broadband_accessType", dealString(object.getString("broadband_accessType")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_status"))))
                                reply.put("broadband_status", dealString(object.getString("broadband_status")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_plane"))))
                                reply.put("broadband_plane", dealString(object.getString("broadband_plane")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_line"))))
                                reply.put("broadband_line", dealString(object.getString("broadband_line")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_direction"))))
                                reply.put("broadband_direction", dealString(object.getString("broadband_direction")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_vpi"))))
                                reply.put("broadband_vpi", dealString(object.getString("broadband_vpi")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_vci"))))
                                reply.put("broadband_vci", dealString(object.getString("broadband_vci")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_port"))))
                                reply.put("broadband_port", dealString(object.getString("broadband_port")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_portRate"))))
                                reply.put("broadband_portRate", dealString(object.getString("broadband_portRate")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_networkElement"))))
                                reply.put("broadband_networkElement", dealString(object.getString("broadband_networkElement")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_deviceIpaddress"))))
                                reply.put("broadband_deviceIpaddress", dealString(object.getString("broadband_deviceIpaddress")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_oltName"))))
                                reply.put("broadband_oltName", dealString(object.getString("broadband_oltName")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_oltIp"))))
                                reply.put("broadband_oltIp", dealString(object.getString("broadband_oltIp")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_oltAssembly"))))
                                reply.put("broadband_oltAssembly", dealString(object.getString("broadband_oltAssembly")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_ponPortAssemblyName"))))
                                reply.put("broadband_ponPortAssemblyName", dealString(object.getString("broadband_ponPortAssemblyName")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_AssemblyCode")))) {
                                String str=dealString(object.getString("broadband_AssemblyCode"));
                                reply.put("broadband_AssemblyCode", str);
                            }
                            if (StringUtils.isBlank(((String) reply.get("broadband_ponPort"))))
                                reply.put("broadband_ponPort", dealString(object.getString("broadband_ponPort")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_ponEncoding"))))
                                reply.put("broadband_ponEncoding", dealString(object.getString("broadband_ponEncoding")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_broadbanInnerLayer"))))
                                reply.put("broadband_broadbanInnerLayer", dealString(object.getString("broadband_broadbanInnerLayer")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_broadbanOuterLayer"))))
                                reply.put("broadband_broadbanOuterLayer", dealString(object.getString("broadband_broadbanOuterLayer")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_limitOutNetAccess"))))
                                reply.put("broadband_limitOutNetAccess", dealString(object.getString("broadband_limitOutNetAccess")));
                            if (StringUtils.isBlank(((String) reply.get("broadband_fstatus"))))
                                reply.put("broadband_fstatus", dealString(object.getString("broadband_fstatus")));

                            //取得资源对象 object
                            log += object.toJSONString();
                        }
                    }


                    if(voicearrayOut!=null&&voicearrayOut.size()>0&&voicearrayOut.getJSONObject(0)!=null) {
                        for (int i = 0; i < voicearrayOut.size(); i++) {
                            JSONObject object = voicearrayOut.getJSONObject(i);
                            voiceExist=0;
                            if (StringUtils.isBlank(((String) reply.get("voice_generalPhone"))))
                                reply.put("voice_generalPhone", dealString(object.getString("voice_generalPhone")));
                            if (StringUtils.isBlank(((String) reply.get("voice_physicalNumber"))))
                                reply.put("voice_physicalNumber", dealString(object.getString("voice_physicalNumber")));
                            if (StringUtils.isBlank(((String) reply.get("voice_customerName"))))
                                reply.put("voice_customerName", dealString(object.getString("voice_customerName")));
                            if (StringUtils.isBlank(((String) reply.get("voice_cornet"))))
                                reply.put("voice_cornet", dealString(object.getString("voice_cornet")));
                            if (StringUtils.isBlank(((String) reply.get("voice_direction"))))
                                reply.put("voice_direction", dealString(object.getString("voice_direction")));
                            if (StringUtils.isBlank(((String) reply.get("voice_status"))))
                                reply.put("voice_status", dealString(object.getString("voice_status")));
                            if (StringUtils.isBlank(((String) reply.get("voice_line"))))
                                reply.put("voice_line", dealString(object.getString("voice_line")));
                            if (StringUtils.isBlank(((String) reply.get("voice_accessType"))))
                                reply.put("voice_accessType", dealString(object.getString("voice_accessType")));
                            if (StringUtils.isBlank(((String) reply.get("voice_plane"))))
                                reply.put("voice_plane", dealString(object.getString("voice_plane")));
                            if (StringUtils.isBlank(((String) reply.get("voice_interfaceAssemblyName"))))
                                reply.put("voice_interfaceAssemblyName", dealString(object.getString("voice_interfaceAssemblyName")));
                            if (StringUtils.isBlank(((String) reply.get("voice_portAssemblyCode")))) {
                                String str=dealString(object.getString("voice_portAssemblyCode"));
                                reply.put("voice_portAssemblyCode", str);
//
                            }
                            if (StringUtils.isBlank(((String) reply.get("voice_fstatus"))))
                                reply.put("voice_fstatus", dealString(object.getString("voice_fstatus")));

                            //取得资源对象 object
                            log += object.toJSONString();
                        }
                    }

                    if(pipinfoarrayOut!=null&&pipinfoarrayOut.size()>0&&pipinfoarrayOut.getJSONObject(0)!=null) {
                        for (int i = 0; i < pipinfoarrayOut.size(); i++) {
                            JSONObject object = pipinfoarrayOut.getJSONObject(i);
                            snExist=0;
                            System.out.println(((String) reply.get("sn_oltEncoding")));
                            if (StringUtils.isBlank(((String) reply.get("sn_oltEncoding"))))
                                reply.put("sn_oltEncoding", dealString(object.getString("sn_oltEncoding")));
                            if (StringUtils.isBlank(((String) reply.get("sn_oltName"))))
                                reply.put("sn_oltName", dealString(object.getString("sn_oltName")));
                            if (StringUtils.isBlank(((String) reply.get("sn_oltIp"))))
                                reply.put("sn_oltIp", dealString(object.getString("sn_oltIp")));
                            if (StringUtils.isBlank(((String) reply.get("sn_ponEncoding"))))
                                reply.put("sn_ponEncoding", dealString(object.getString("sn_ponEncoding")));
                            if (StringUtils.isBlank(((String) reply.get("sn_ponName"))))
                                reply.put("sn_ponName", dealString(object.getString("sn_ponName")));
                            if (StringUtils.isBlank(((String) reply.get("sn_broadbandPVLAN"))))
                                reply.put("sn_broadbandPVLAN", dealString(object.getString("sn_broadbandPVLAN")));
                            if (StringUtils.isBlank(((String) reply.get("sn_tvPVLAN"))))
                                reply.put("sn_tvPVLAN", dealString(object.getString("sn_tvPVLAN")));
                            if (StringUtils.isBlank(((String) reply.get("sn_broadbandCVLAN"))))
                                reply.put("sn_broadbandCVLAN", dealString(object.getString("sn_broadbandCVLAN")));
                            if (StringUtils.isBlank(((String) reply.get("sn_tvCVLAN"))))
                                reply.put("sn_tvCVLAN", dealString(object.getString("sn_tvCVLAN")));
                            if (StringUtils.isBlank(((String) reply.get("sn_OLTgroupName"))))
                                reply.put("sn_OLTgroupName", dealString(object.getString("sn_OLTgroupName")));
                            if (StringUtils.isBlank(((String) reply.get("sn_OLTgroupCode"))))
                                reply.put("sn_OLTgroupCode", dealString(object.getString("sn_OLTgroupCode")));
                            if (StringUtils.isBlank(((String) reply.get("sn_PONgroupName"))))
                                reply.put("sn_PONgroupName", dealString(object.getString("sn_PONgroupName")));
                            if (StringUtils.isBlank(((String) reply.get("sn_PONgroupCode")))) {
                                String str=dealString(object.getString("sn_PONgroupCode"));
                                reply.put("sn_PONgroupCode", str);
                                ponid=getPONID(str);
                            }


                            //取得资源对象 object
                            log += object.toJSONString();
                        }
                    }

                    reply.put("itvExist",itvExist);
                    reply.put("broadbandExist",broadbandExist);
                    reply.put("voiceExist",voiceExist);
                    reply.put("snExist",snExist);

                    reply.put("PONID",ponid);
                    reply.put("flag", "0");
                    reply.put("log", log);
                    return reply;

                }else {
                    reply.put("flag","1");
                    reply.put("log", "资源服务器返回失败");
                    return reply;
                }
            }else {
                reply.put("flag","1");
                reply.put("log", "资源请求无响应");
                return reply;
            }
        }catch (Exception e) {
            e.printStackTrace();
            reply.put("flag","1");
            reply.put("log", e.toString());
            return reply;
        }
    }

    public  static String dealString(String str){
       return str==null ? "" : str;
    }

    public static void main(String[] args){
        String a="{\"voice\":[],\"flag\":0,\"broadband\":[{\"broadband_broadbandAccount\":\"13395867097\",\"broadband_customerName\":\"叶慧\",\"broadband_snNumber\":\"5765SN200710267\",\"broadband_serviceNumber\":\"5761UBD24941280\",\"broadband_accessType\":\"FTTH\",\"broadband_status\":\"归档\",\"broadband_plane\":null,\"broadband_line\":null,\"broadband_direction\":null,\"broadband_vpi\":null,\"broadband_vci\":null,\"broadband_port\":\"3\",\"broadband_portRate\":\"100Mbps\",\"broadband_networkElement\":\"楚门新局/华为E8-C-5765SN200710267\",\"broadband_deviceIpaddress\":null,\"broadband_oltName\":\"玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"broadband_oltIp\":\"10.132.13.51\",\"broadband_oltAssembly\":\"楚门新局Z01/玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"broadband_ponPortAssemblyName\":\"00/2/05\",\"broadband_AssemblyCode\":\"00/2/05\",\"broadband_ponPort\":\"未录入\",\"broadband_ponEncoding\":\"05\",\"broadband_broadbanInnerLayer\":\"681\",\"broadband_broadbanOuterLayer\":\"460\",\"broadband_limitOutNetAccess\":null,\"broadband_fstatus\":\"归档\"}],\"pipinfo\":[{\"sn_oltEncoding\":\"YH-OLT-CM-HWMA5680T-18(GFTTH)\",\"sn_oltName\":\"玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"sn_oltIp\":\"10.132.13.51\",\"sn_ponEncoding\":\"05\",\"sn_ponName\":\"未录入\",\"sn_broadbandPVLAN\":\"460\",\"sn_tvPVLAN\":\"2052\",\"sn_broadbandCVLAN\":\"681\",\"sn_tvCVLAN\":null,\"sn_OLTgroupName\":\"楚门新局Z01/玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"sn_OLTgroupCode\":\"YCM.CMXJ0Z01/YH-OLT-CM-HWMA5680T-18(GFTTH)\",\"sn_PONgroupName\":\"00/2/05\",\"sn_PONgroupCode\":\"00/2/05\"}],\"itv\":[{\"itv_broadbandAccount\":\"tv1576113466041085@itv\",\"itv_customerName\":\"叶慧\",\"itv_snNumber\":\"5765SN200710267\",\"itv_serviceNumber\":\"1576113466041085\",\"itv_accessType\":\"FTTH\",\"itv_status\":\"归档\",\"itv_plane\":null,\"itv_line\":null,\"itv_direction\":null,\"itv_vpi\":null,\"itv_vci\":null,\"itv_port\":\"4\",\"itv_portRate\":\"50Mbps\",\"itv_networkElement\":\"楚门新局/华为E8-C-5765SN200710267\",\"itv_deviceIpaddress\":null,\"itv_oltName\":\"玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"itv_oltIp\":\"10.132.13.51\",\"itv_oltAssembly\":\"楚门新局Z01/玉环-OLT-楚门-HWMA5680T-18(GFTTH)\",\"itv_ponPortAssemblyName\":\"00/2/05\",\"itv_AssemblyCode\":\"00/2/05\",\"itv_ponPort\":\"未录入\",\"itv_ponEncoding\":\"05\",\"itv_tvInnerLayer\":\"2109\",\"itv_tvOuterLayer\":\"2052\",\"itv_limitOutNetAccess\":null,\"itv_fstatus\":\"归档\"}]}";


        Map<String,Object> map=getRES(a);
        System.out.println(map.get("flag"));
        System.out.println(map.get("itv_fstatus"));
//        System.out.println(getPONID("01/11/01"));
    }


    public static String doPost(String url, String account)throws Exception {
        String html = "";
        HttpClient httpClient = new HttpClient();
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(7000);
        httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000);

        PostMethod postMethod = new PostMethod(url+"?accesscode="+account);
        postMethod.setRequestHeader("accept", "*/*");
        postMethod.setRequestHeader("connection", "Keep-Alive");
        postMethod.setRequestHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
        postMethod.setRequestHeader("Accept-Language", "zh-cn,zh;q=0.5");
        postMethod.setRequestHeader("Accept-Encoding", "gzip,deflate");
        postMethod.setRequestHeader("Content-Type", "text/html;charset=utf-8");
        // 填入各个表单域的值
        //NameValuePair[] data = { new NameValuePair("accesscode", account) };
        // 将表单的值放入postMethod中
        //postMethod.setRequestBody(data);
        // 执行postMethod
        int statusCode = httpClient.executeMethod(postMethod);
        // HttpClient对于要求接受后继服务的请求，象POST和PUT等不能自动处理转发
        // 301或者302
        if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
            // 从头中取出转向的地址
            Header locationHeader = postMethod.getResponseHeader("location");
            String location = null;
            if (locationHeader != null) {
                location = locationHeader.getValue();
                System.out.println("The page was redirected to:" + location);
            } else {
                System.err.println("Location field value is null.");
            }
            return html;
        }

        if(postMethod.getStatusCode()==404){
            return "404";
        }


        BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod
                .getResponseCharSet()));
        StringBuffer sb = new StringBuffer();
        int chari;
        while ((chari = in.read()) != -1) {
            sb.append((char) chari);
        }
        html = sb.toString();
        in.close();
        return html;
    }


    private static String getPONID(String str) {
        String ponid="";
//        01/11/01

            if (StringUtils.isNotBlank(str)) {
                String list[] = str.split("/");
                if (list.length == 3) {
                    //System.out.println("NA-0-"+list[1]+"-"+list[2]);
                    if (!list[1].equals("NA")) {
                        list[1] = String.valueOf(Integer.parseInt(list[1]));
                    }
                    if (!list[2].equals("NA")) {
                        list[2] = String.valueOf(Integer.parseInt(list[2]));
                    }
                    ponid="NA-0-"+ list[1] + "-" + list[2];
                }
            }

        return ponid;
    }




}
